<template>
    <div class="goodsEntry">
            <div style="padding:20px">
                    <el-button type="primary" @click="returnOver">返回</el-button>
            </div>
        <div style="padding:20px;height:30px">
            <!-- <span>盘点编号：</span>
            <span>仓库：</span> -->
            <el-button type="primary" size="medium" @click="Keepinventory" style="float:right">保存盘点结果</el-button>
        </div>
        <!-- <el-form :inline="true" style="padding: 0 20px">
                <el-form-item label="盘点编号：">
                </el-form-item>
                <el-form-item label="">
                </el-form-item>
                <el-form-item label="">
                <el-button type="primary" size="medium" @click="smentry()">保存盘点结果</el-button>
                </el-form-item>
        </el-form> -->
        <el-form :inline="true" style="padding: 0 20px">
            <el-form-item label="">
            <el-input v-model="goodsId" autofocus @keyup.enter.native="smentry"  style="width:250px" placeholder="请录入商品ID"></el-input>
            </el-form-item>
            <el-form-item label="">
            <el-button type="primary" size="medium" @click="smentry()">确定录入</el-button>
            </el-form-item>
        </el-form>
        <div class="wrapper">
                <el-table class="table" :data="tableData" stripe highlight-current-row border>
                    <el-table-column
                    type="index"
                    width="50">
                  </el-table-column>
                  <!-- <el-table-column align="center" type="selection">
                  </el-table-column> -->
                  <el-table-column align="center" prop="goods_no" label="商品编号">
                  </el-table-column>
                  <el-table-column align="center" prop="goods_name" label="商品名称">
                  </el-table-column>
                  <el-table-column align="center" prop="sku_no" label="SKU编码">
                  </el-table-column>
                  <el-table-column align="center" prop="odorType" label="香型">
                  </el-table-column>
                  <el-table-column align="center" prop="netContent" label="净含量">
                  </el-table-column>
                  <el-table-column align="center" prop="alocohl" label="酒精度">
                    </el-table-column>
                 <el-table-column align="center" prop="unit" label="单位">
                  </el-table-column>
                  
                  <el-table-column align="center" prop="systemPcs" label="系统数量">
                  </el-table-column>
                  
                  <el-table-column align="center" prop="checkPcs" label="盘点数量">
                  </el-table-column>
                  <el-table-column align="center" prop="outPcs" label="盘赢">
                  </el-table-column>
                  <el-table-column align="center" prop="diffPcs" label="盘亏">
                    </el-table-column>
                  <!-- <el-table-column align="center" prop="operator_username" label="备注"  width="300">
                      <template slot-scope="scope">
                         <el-input v-model="remarks" placeholder="请输入备注"></el-input>
                        </template>
                  </el-table-column> -->
                  <!-- <el-table-column align="center" prop="description" label="明细备注" width="300">
                      <template slot-scope="scope">
                              <el-input v-model="remarks" placeholder="请输入备注"  @keyup.enter.native="writeinfos(scope.row)" v-if="remarksone"></el-input>
                              <span @click="istest(scope.row)" v-if="remarkstwo">{{scope.row.description}}</span>
                          </template>
                </el-table-column> -->
                <el-table-column align="center" prop="description" label="明细备注" width="300">
                    <template slot-scope="scope">
                            <el-button
                            size="mini"
                            type="primary" plain
                            @click="istest(scope.row)" v-if="scope.row.description == ''">添加备注</el-button>
                           
                            <span class="canceloff-btn" @click="istest(scope.row)" style="color:blue" v-else>{{scope.row.description}}</span>
                        </template>

              </el-table-column>
                  <el-table-column align="center" prop="address" label="操作" width="150">
                    <template slot-scope="scope">
                      <span class="canceloff-btn" @click="Seeinfo(scope.row)">查看</span>
                    </template>
                  </el-table-column>
                </el-table>
                <!-- <el-pagination background layout="total,prev, pager, next,jumper" :page-size="page.pageSize" :total="page.total" :current-page="page.current"
                  @current-change="handleCurrentChange">
                </el-pagination> -->
                <div style="height:80px">
                        <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page.current"
                        :page-sizes="[10,20,30]"
                        :page-size="page.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="page.total">
                      </el-pagination>
                </div>
                
              </div>
              <audio id="myaudio" src="../../../../viode/004.mp3" controls="controls" hidden="hidden" ></audio>
              <audio id="warn" src="../../../../viode/warn.mp3" controls="controls"  hidden="hidden"></audio>
              <div>
                <el-form :inline="true" style="padding: 0 20px;width:300px">
                        <el-form-item label=""  >
                            <el-input type="textarea" v-model="desc" style="width:800px" placeholder="请输入单据备注" @keyup.enter.native="zremas"></el-input>
                        </el-form-item>
                        </el-form>
              </div>
              <el-dialog :title="titleb" :visible.sync="dialogFormVisible">
                  <el-form>
                      <el-form-item label="">
                          <el-input v-model="remarks" placeholder="请输入备注"  @keyup.enter.native="writeinfos(scope.row)"></el-input>
                      </el-form-item>
                   
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="sureData">确 定</el-button>
                  </div>
                </el-dialog>
                <el-dialog
                title="提示"
                :visible.sync="deteldialogVisible"
                width="30%"
                :before-close="handleClose">
                <span>是否确定保存此次盘点结果?</span>
                <span slot="footer" class="dialog-footer">
                  <el-button @click="detal">删除</el-button>
                  <el-button type="primary" @click="Preservation">保存</el-button>
                </span>
              </el-dialog>
    </div>
</template>
<script>
    export default{
        data(){
            return{
                tableData: [],
                page: {
                pageSize: 10,
                current: 1,
                total: null
              },
              goodsId:'',
              storeId:this.$route.query.id,
              remarks:'',
              remarkstwo:true,
              remarksone:false,
              dialogFormVisible:false,
              titleb:'',
              descId:'',
              desc:'',
              deteldialogVisible:false
            }
        },
        mounted () {
          this.inintable();
          
        },
        methods: {
             //扫描入库
          async factoryGoods() {
              try {
                let { data } = await this.$post({
                  api: "/check/scan/goodsId",
                  data:{
                    goodsId:this.goodsId,
                    storeId:this.storeId,
                   
                  }
                });
                if (data.code === 0) {
                  this.inintable();
                  this.$message({
                  type: "success",
                  message: data.msg
                 });
                
                 this.autoplays();
                } else {
                  this.$message({
                    type: "error",
                    message: data.msg
                  });
                  this.warnplay();
                }
              } catch (e) {
                // this.$message({
                //   type: "error",
                //   message: "接口报错"
                // });
              }
           },
            //二维码录入
          smentry(){
            if(this.storeId == '' && this.inputAreaId == ''){
              this.$message({
                  type: "error",
                  message: '请选择仓库和货位'
                 });
            }else{
              this.factoryGoods();
              this.goodsId = '';
            }
          },
          //音频录入
          autoplays(){
             let audio =  document.getElementById('myaudio')
             audio.currentTime = 0
             audio.play();
            // this.$netxTick(function(){
              // console.log(document.getElementById('myaudio'), 999)
               
            //  })
           },
           //
           warnplay(){
             let warn = document.getElementById('warn');
             warn.currentTime = 0
             warn.play();
           },
            returnOver(){
              this.deteldialogVisible = true;
              // this.$confirm("是否确定保存此次盘点结果?", "系统提示", {
              //   confirmButtonText: "保存",
              //   cancelButtonText: "删除",
              //   type: "warning"
              // }).then(() => {
              //   //保存
              //   this.checkrecord();
                
              // }).catch(() => {
              //   //删除
              //   this.deletecheck();
              // });
               
            },
            //删除
            detal(){
              this.deletecheck();
            },
            //保存
            Preservation(){
              this.checkrecord();
            },
            Seeinfo(row){
                this.$router.push({path:'/beginCheckdetails',query:{id:this.storeId,skuid:row.sku_no}});
            },
            //保存
            Keepinventory(){
               this.checkrecord();
              //  this.$router.push({path:'/DistilleryInventory'});
            },
            handleSizeChange(val){
              this.page.current = val;
              this.inintable();
            },
            handleCurrentChange(){
              this.page.pageSize = val;
              this.inintable(); 
            },
            async inintable(){
              try{
                  let {data} = await this.$post({
                      api:'/show/allcheck',
                      data:{
                          current:this.page.current,
                          pageSize:this.page.pageSize,
                          checkNo:'',
                          startTime:'',
                          endTime:'',
                          checkStatus:0
                      }
                  })
                  if(data.code === 0){
                      this.tableData = data.data;
                      this.page.total = data.rdPage.total;
                      console.log(data)
                  }
              }catch(error){

              }
          },
          async checkinfo(){
              try{
                  let {data} = await this.$post({
                      api:'/update/checkinfo',
                      data:{
                        id:'',
                        info:''
                      }
                  })
                  if(data.code === 0){
                    this.$message({
                      type: "success",
                      message: data.msg
                    });
                    
                      
                  }else{
                    this.$message({
                      type: "error",
                      message: data.msg
                    });
                  }
              }catch(error){

              }
          },
          writeinfos(){

          },
          //保存盘点结果
          async checkrecord(){
              try{
                  let {data} = await this.$post({
                      api:'/save/checkrecord',
                      data:{
                        storeId:this.$route.query.id,
                        info:this.desc
                      }
                  })
                  if(data.code === 0){
                    this.$message({
                      type: "success",
                      message: data.msg
                    });
                    this.$router.push({path:'/DistilleryInventory'});
                      
                  }else{
                    this.$message({
                      type: "error",
                      message: data.msg
                    });
                  }
              }catch(error){

              }
          }, 
          async checkinfo(id){
              try{
                  let {data} = await this.$post({
                      api:'/update/checkinfo',
                      data:{
                        id:id,
                        info:this.remarks
                      }
                  })
                  if(data.code === 0){
                    this.$message({
                      type: "success",
                      message: data.msg
                    });
                    this.dialogFormVisible = false;
                    this.inintable();
                      
                  }else{
                    this.$message({
                      type: "error",
                      message: data.msg
                    });
                  }
              }catch(error){

              }
          }, 
          async resultinfo(id){
              try{
                  let {data} = await this.$post({
                      api:'/update/resultinfo',
                      data:{
                        checkNo:'',
                        info:this.desc
                      }
                  })
                  if(data.code === 0){
                    this.$message({
                      type: "success",
                      message: data.msg
                    });
                    this.dialogFormVisible = false;
                    this.inintable();
                      
                  }else{
                    this.$message({
                      type: "error",
                      message: data.msg
                    });
                  }
              }catch(error){

              }
          }, 
          //删除列表
          async deletecheck(id){
              try{
                  let {data} = await this.$post({
                      api:'/delete/check',
                      data:{
                        storeId:this.$route.query.id
                      }
                  })
                  if(data.code === 0){
                    this.$message({
                      type: "success",
                      message: data.msg
                    });
                   
                    this.$router.go(-1);
                      
                  }else{
                    this.$message({
                      type: "error",
                      message: data.msg
                    });
                  }
              }catch(error){

              }
          },
          istest(row){
            this.descId = row.id
                   
                   if(row.description == ''){
                       this.titleb = '添加备注'
                   }else{
                   this.titleb = '修改备注'
                   }
                this.dialogFormVisible = true;
                this.remarks  = row.description;
          },
          sureData(){
            this.checkinfo(this.descId);
          },
          zremas(){
            
          }
        }
    }
</script>
<style>
   .goodsEntry{
       margin: 20px;
   }
</style>